package com.loan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.loan.entity.Emp;
import com.loan.mappers.EmpMapper;
import com.loan.mappers.PermMapper;
import com.loan.mappers.RolePermMapper;
import com.loan.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpImpl extends ServiceImpl<EmpMapper, Emp> implements EmpService {



    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private RolePermMapper rolePermMapper;

    @Override
    public void addEmp(Emp emp, Integer[] perm) {
        emp.setStatus("y");
        empMapper.addEmp(emp);
        for(int per : perm){
            rolePermMapper.add(emp.getRoleid(),per);
        }
    }

    @Override
    public void deleteStatus(int empid) {
        empMapper.deleteStatus(empid);
    }

    @Override
    public List<Emp> getAll() {
        List<Emp> all = empMapper.getAll();
        return all;
    }

    @Override
    public Emp getEmpAccount(String account) {
        Emp empAccount = empMapper.getEmpAccount(account);
        return empAccount;
    }

    @Override
    public void updateEmp(Emp emp, Integer[] perms) {
        empMapper.updateEmp(emp);
        rolePermMapper.delByRoleId(emp.getRoleid());
        for(int perm : perms){
            rolePermMapper.add(emp.getRoleid(),perm);
        }
    }
}
